// window滚动显示返回顶部按钮及视差滚动
let parallax = document.querySelector('.parallax')
let parallaxText = document.querySelector('.parallaxText');
let backTop = document.querySelector(".backTop");
// 导航栏部分变量
let header = document.querySelector('header');
let navLogo = document.querySelector('.logo_img_container > img');
let overlap = document.querySelector('.overlap');
backTop.addEventListener('click',function(){
    header.style.transform = `translateY(0%)`;
    window.scrollTo({
      top:0,
      behavior:"smooth",
    });
  });
// 头部滚动隐藏与显示
window.addEventListener('mousewheel',mousewheel);
function mousewheel(e){
    e = e || window.event;
    if(e.wheelDelta < 0 && e.wheelDelta - 1 < 0){
        header.style.transform = `translateY(-100%)`;
    };
    if(e.wheelDelta > 0 && e.wheelDelta +1 > 0){
        header.style.transform = `translateY(0%)`;
        if(overlap.getBoundingClientRect().top < 79){
            header.className = "whiteNavBar" ;
            navLogo.src = "https://gw.alipayobjects.com/zos/bmw-prod/fae9a7a0-0800-4655-b8b5-af3150233bdf.svg";
        }else{
            header.className = 'transparentNavBar';
            navLogo.src = "https://gw.alipayobjects.com/zos/bmw-prod/25d46cbf-7f0f-4745-a6c5-75d977f8c1a5.svg";
        }
    };
};
// 浏览器滚动事件
window.addEventListener("scroll",function(){
    let scrollVue = document.documentElement.scrollTop;
    // 视差滚动
    let parallaxHeight = parallax.offsetHeight;
    scrollVue <= parallaxHeight ? parallax.style.transform = `translateY(${scrollVue}px)` : parallax.style.transform = `translateY(${parallaxHeight}px)`;
    scrollVue <= 770 ? parallaxText.style.transform = `translateY(-${scrollVue / 3.5}px)` : parallaxText.style.transform = `translateY(-${285}px)`;

    // 回到顶部按钮
    if(scrollVue > 400){
      backTop.style.opacity = 1;
    }else{
        backTop.style.opacity = 0;
    }
    if(overlap.getBoundingClientRect().top < 79){
      header.className = 'whiteNavBar';
    }else{
      header.className = 'transparentNavBar';
      navLogo.src = "https://gw.alipayobjects.com/zos/bmw-prod/25d46cbf-7f0f-4745-a6c5-75d977f8c1a5.svg";
    };
});